<?php
/**
 * Created by PhpStorm.
 * User: reshared
 * Date: 17-7-21
 * Time: 下午11:23
 */

namespace App\Http\Controllers\Home;


use App\Http\Controllers\Controller;
use App\Repository\ArticleRepository;
use App\Repository\TagRepository;
use Illuminate\Http\Request;

class HomeController extends Controller
{
    protected $request;
    protected $articleRepository;
    protected $tagRepository;

    public function __construct(ArticleRepository $articleRepository, TagRepository $tagRepository, Request $request)
    {
        $this->request = $request;
        $this->articleRepository = $articleRepository;
        $this->tagRepository = $tagRepository;
    }

    public function index()
    {
        $items = $this->articleRepository->getIndexArticles(10);
        $title = '这是一个非常简单的博客';
        $bg = 'img/home-bg.jpg';
        return view('home.index', compact('items', 'title', 'bg'));
    }

    public function blog()
    {
        $title = '博文-God Bless U';
        $bg = 'img/blog.jpg';
        $items = $this->getItems('blog');
        return view('home.blog', compact('title', 'items', 'bg'));
    }

    public function xs()
    {
        $title = '劣质小说，诸位见笑-God Bless U';
        $bg = 'img/xs-bg.jpg';
        $items = $this->getItems('xs');
        return view('home.blog', compact('title', 'items', 'bg'));
    }

    public function gb()
    {
        $title = '偶尔的一些浆糊里的风暴-God Bless U';
        $bg = 'img/gb-bg.jpg';
        $items = $this->getItems('gb');
        return view('home.blog', compact('title', 'items', 'bg'));
    }

    public function sb()
    {
        $title = '不是傻X,是随便-God Bless U';
        $bg = 'img/sb-bg.jpg';
        $items = $this->getItems('gb');
        return view('home.blog', compact('title', 'items', 'bg'));
    }

    private function getItems($name, $number = 10)
    {
        $tag = $this->tagRepository->getTag($name);
        return $this->articleRepository->getList($tag->tid, $number);
    }
}